package com.orangelife.mobile.parkingfee.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.curry.orangelife.mobile.R;
import com.curry.android.adapter.FatherAdapter;
import com.orangelife.mobile.util.DateUtil;

/**
 * 我的停车费列表的适配器
 * 
 * @author lxj
 * 
 */
public class ParkingFeeListViewAdapter<T> extends FatherAdapter<T> {

	private Context context;
	private List<Map<String, Object>> list;

	public ParkingFeeListViewAdapter(Context context,
			List<Map<String, Object>> list) {

		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressWarnings("unchecked")
	@Override
	public BaseAdapter setList(List<T> list) {
		this.list = (List<Map<String, Object>>) list;
		return ParkingFeeListViewAdapter.this;
	}

	@SuppressWarnings("unchecked")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_parking_fee, null);
			holder.tvOrderNum = (TextView) convertView
					.findViewById(R.id.tvOrderNum);
			holder.tvParking = (TextView) convertView
					.findViewById(R.id.tvParkingLot);
			holder.tvLicense = (TextView) convertView
					.findViewById(R.id.tvLicensePlate);
			holder.tvMoney = (TextView) convertView.findViewById(R.id.tvMoney);
			holder.tvTime = (TextView) convertView.findViewById(R.id.tvTime);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		DateUtil dateUtil = new DateUtil();
		String time = dateUtil.tranStringForDate(list.get(position)
				.get("tscreate").toString());

		holder.tvOrderNum.setText(list.get(position).get("orderID").toString());
		holder.tvParking
				.setText(list.get(position).get("parkName").toString());
		holder.tvLicense.setText(list.get(position).get("remark").toString());
		holder.tvMoney.setText(list.get(position).get("totalCost").toString());
		holder.tvTime.setText(time);
		return convertView;
	}

	class ViewHolder {
		/** 订单号 */
		private TextView tvOrderNum;
		/** 车位 */
		private TextView tvParking;
		/** 车牌号 */
		private TextView tvLicense;
		/** 金额 */
		private TextView tvMoney;
		/** 时间 */
		private TextView tvTime;
	}

}
